package com.su.lightthings.base

import android.os.Bundle
import android.util.Log
import androidx.lifecycle.Observer
import com.jeremyliao.liveeventbus.LiveEventBus
import com.su.lightthings.utils.Cons

open class NetStateActivity : BaseActivity() {
    private val TAG = "NetStateActivity"
    private var isConnect = false
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.d(TAG, "NetStateActivity onCreate: ")
        regNetworkStateListener()
    }

    private fun regNetworkStateListener() {
        LiveEventBus
            .get(Cons.LiveDataBus.NET_STATE, Boolean::class.java)
            .observe(this, Observer {
                Log.d(TAG, "网络状态发生改变: $it")
                isConnect = it
            })
    }

    fun isNetworkConnected(): Boolean = isConnect
}